package org.example.demoarticle.Service.impl;

import org.example.demoarticle.Mapper.UserMapper;
import org.example.demoarticle.Service.UserService;
import org.example.demoarticle.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;
    @Override
    public User login(User user) {
        return userMapper.gerByUserNameAndPassword(user);
    }

    @Override
    public User profile(String username) {
        return userMapper.getByName(username);
    }

    @Override
    public String getType(String username) {
        return userMapper.getType(username);
    }

    @Override
    public int updatePassword(String username, String password, String newPassword) {
        User user = userMapper.getByName(username);
        if(user.getPassword().equals(password)) {
           return userMapper.updatePassword(username,newPassword);
        }
        return 0;
    }
}
